/***********************************************************************
 * Copyright sf.
 * All rights reserved. 
 *
 * HISTORY
 ***********************************************************************
 *  ID       DATE                PERSON            REASON
 *  1      2009-08-05             azure             修改
 
 ************************************************************************
 */
package com.newbingo.action;

import java.util.Date;
import com.googlecode.jsonplugin.annotations.JSON;
import com.newbingo.entity.Affiche;
import com.newbingo.service.imple.IAfficheService;
import com.newbingo.util.Pager;
import com.opensymphony.xwork2.ActionSupport;


@SuppressWarnings("serial")
public class AfficheAction extends ActionSupport {
	private Pager pager=null;
	private IAfficheService afficheService=null;
	private Affiche affiche;
	
	/*分页条件*/
	private int start;
	private int limit;
	
	/*查询条件  
	 * type 公告查询
	 * dynaType 动态显示公告条件
	 * */
	private Integer type;
	private Integer dynaType;

	/*判断方法执行是否正确
	 * 
	 * 每个action都需要，页面会获得这个信息来提示用户返回时候正确
	 * */
	private Boolean success=false;
	
	/*
	 * 公告更新传值
	 * */
	private Integer affId;
	private String title;
	private String contents;

	/**
	 * 新增公告
	 * */
	public String create(){
		this.getAffiche().setCreateTime(new Date());
		afficheService.createAffiche(this.getAffiche());
		success=true;
		return SUCCESS;
	}
	
	/**
	 * 编辑公告
	 * */
	public String update(){
		affiche = afficheService.findById(affId);
		if(null==affiche){
			
			success=false;
			
		}else{
			
			affiche.setTitle(title);
			affiche.setContents(contents);
			affiche.setType(type);
			
			afficheService.updateAffiche(affiche);
			success=true;
			
		}

		return SUCCESS;
	}
	
	public String delete(){
		afficheService.deleteAffiche(affiche);
		success=true;
		return SUCCESS;
	}
	
	/**
	 * 查询公告
	 * */
	public String findByPage(){
		this.setPager(afficheService.findByPage(start, limit, type));
		success=true;
		return SUCCESS;
	}
	
	/**
	 * 主页面的内部公告动态加载查询
	 * 
	 * 暂时发想Ext的TaskMgr会一直传默认的type只，导致查询所有公告是出现问题
	 * 
	 * 暂时解决法案
	 * */
	public String findDynaByPage(){
		System.out.println("type=="+dynaType);
		this.setPager(afficheService.findByPage(start, limit, dynaType));
		success=true;
		return SUCCESS;
	}
	
	public Boolean getSuccess() {
		return success;
	}
	public void setSuccess(Boolean success) {
		this.success = success;
	}
	@JSON(name="affes")
	public Pager getPager() {
		return pager;
	}
	public void setPager(Pager pager) {
		this.pager = pager;
	}
	
	@JSON(serialize=false)
	public IAfficheService getAfficheService() {
		return afficheService;
	}
	public void setAfficheService(IAfficheService afficheService) {
		this.afficheService = afficheService;
	}
	
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	
	public Integer getDynaType() {
		return dynaType;
	}
	public void setDynaType(Integer dynaType) {
		this.dynaType = dynaType;
	}
	public Affiche getAffiche() {
		return affiche;
	}
	public void setAffiche(Affiche affiche) {
		this.affiche = affiche;
	}
	
	public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getLimit() {
		return limit;
	}
	public void setLimit(int limit) {
		this.limit = limit;
	}

	public Integer getAffId() {
		return affId;
	}

	public void setAffId(Integer affId) {
		this.affId = affId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContents() {
		return contents;
	}

	public void setContents(String contents) {
		this.contents = contents;
	}
	
}
